// components/like/like.js
Component({
  /**
   * Component properties
   */
  properties: {
    like: {
      type: Boolean
    },
    count: {
      type: Number
    }
  },

  /**
   * Component initial data
   */
  data: {
    onlike: 'images/like.png',
    dislike: 'images/like@dis.png'
  },

  /**
   * Component methods
   */
  methods: {
    onLike: function (e) {
      let like = this.properties.like
      let count = this.properties.count
      count = like ? count - 1 : count + 1
      this.setData({
        count: count,
        like: !like
      })
      // 自定义事件
      let behavior = this.properties.like ? 'like' : 'dislike'
      // 激活事件
      this.triggerEvent('like', {
        behavior: behavior
      }, {})
    }
  }
})
